package cn.wolfcode.car.business.web.controller;


import cn.wolfcode.car.business.domain.Statement;
import cn.wolfcode.car.business.domain.StatementItem;
import cn.wolfcode.car.business.query.StatementItemQuery;
import cn.wolfcode.car.business.query.StatementQuery;
import cn.wolfcode.car.business.service.IStatementItemService;
import cn.wolfcode.car.business.service.IStatementService;
import cn.wolfcode.car.common.base.page.TablePageInfo;
import cn.wolfcode.car.common.web.AjaxResult;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


// /business/statementItem/itemDetail?statementId=1
@Controller
@RequestMapping("business/statementItem")
public class StatementItemController {

    // 模板前缀
    private static final String prefix = "business/statementItem/";

    @Autowired
    private IStatementService statementService;
    @Autowired
    private IStatementItemService statementItemService;



    @RequestMapping("/itemDetail")
    public String itemDetail(Model model,Long statementId){

        // 根据id 查询数据
        Statement statement = statementService.get(statementId);
        model.addAttribute("statement",statement);
        // 判断是消费中还是已支付
        if(Statement.STATUS_CONSUME.equals(statement.getStatus())){
            return prefix + "itemEdit";//去编辑明细页面
        }else{
            return prefix + "itemDetail";//去查询详情页面
        }

    }


    //列表
    @RequestMapping("/query")
    @ResponseBody
    public TablePageInfo<StatementItem> query(StatementItemQuery qo){
        return statementItemService.query(qo);
    }


    //结算明细保存
    @RequestMapping("/saveItems")
    @ResponseBody
    public AjaxResult saveItem(@RequestBody List<StatementItem> list){
        statementItemService.saveItem(list);
        return AjaxResult.success();
    }

    //(结算明细)支付
    @RequestMapping("/pay")
    @ResponseBody
    public AjaxResult pay(Long statementId){
        statementItemService.pay(statementId);
        return AjaxResult.success();
    }



}
